import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import {ValidationPipe} from "@nestjs/common";
import {ResponseInterceptor} from "./interceptors/response.interceptor";
import {HttpExceptionFilter} from "./filters/http-exception.filter";

async function bootstrap() {
    const app = await NestFactory.create(AppModule);

    // 全局验证管道
    app.useGlobalPipes(new ValidationPipe({
        whitelist: true, // 自动取出DTO中不存在的字段
        forbidNonWhitelisted: true, // 禁止未知字段
    }));

    // 注册全局响应拦截
    app.useGlobalInterceptors(new ResponseInterceptor());

    //  注册全局异常过滤器
    app.useGlobalFilters(new HttpExceptionFilter());

    await app.listen(process.env.PORT ?? 5151);
}

bootstrap();
